moduleLearningMap.controller('LanguageDetailQuery', function ($stateParams, $state, ConstantService, LanguageService, GeneralResource, $$CambioConfig, $scope, $log, LoadingService, DialogService, LanguageResource) {
    initPage($scope);

    $scope.$on("$viewContentLoaded", function () {
        pageOnLoad($scope);
        ConstantService.addState($state.current, true, LanguageService.language('语言详细列表'));
        $scope.languageViewId = $stateParams.languageViewId;
        $scope.loadDetail();
    });


    $scope.loadDetail = function () {
        LanguageResource.detail({id: $scope.languageViewId}, {}, function (result) {
            $scope.details = result.data;
            $scope.refreshExportTable();
        })
    }

    $scope.update = function () {
        Alert.confirm(function () {
            LanguageResource.update({id: $scope.languageViewId}, $scope.details, function () {
                Alert.success();
            });
        })
    }

    $scope.openDetail = function (record) {
        $scope.currentRecord = record;
        DialogService.open("languageDetailMgt", $scope, function () {
            // $scope.loadDetail();
        });
    }

    $scope.refreshExportTable = function () {
        $("#languageDatas").empty();
        $('#languageDatas').append('<tr><th>KEY</th><th>VALUE</th></tr>');
        // $("#languageDatas  tr:not(:first)").empty("");
        for (var i = 0; i < $scope.details.length; i++) {
            addCurrentRow($scope.details[i]);
        }
    }

    $scope.export = function () {
        $("#languageDatas").table2excel({
            exclude: ".noExl", //过滤位置的 css 类名
            filename: new Date().getTime() + ".xls", //文件名称
            name: "Excel Document Name.xls",
            exclude_img: true,
            exclude_links: true,
            exclude_inputs: true
        });
    }


    function addCurrentRow(row) {
        var val;
        if (row.value) {
            val = row.value;
        } else {
            val = ' ';
        }
        var trcomp = "<tr><td>" + row.key + "</td><td>" + val + "</td></tr>";
        $("#languageDatas tr:last-child").after(trcomp);
    }
});